home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PHRO.ZIP / MUSIC.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-21  |  4KB  |  198 lines

  1. {   High-Level Music Control Source File       }
  2. {   PHRO!                                      }
  3. {   Phred/OTM                                  }
  4. {   achalfin@uceng.uc.edu                      }
  5. {   DO NOT DISTRIBUTE THIS SOURCE FILE         }
  6. Unit Music;
  7.  
  8. { $DEFINE NoTune}
  9. { $DEFINE TEST}
  10.  
  11.  
  12. Interface
  13.  
  14. Var
  15.   SoundEnabled : Boolean;
  16.  
  17. Procedure InitializeMusic;
  18. Procedure BeginMusic;
  19. Procedure CloseMusic;
  20.  
  21. Implementation
  22.  
  23. Uses Crt, MSE_TP;
  24.  
  25. Procedure BeginMusic;
  26.  
  27. Begin
  28.   If SoundEnabled
  29.     Then StartMusic;
  30. End;
  31.  
  32. Function SelectSoundCard : Integer;
  33.  
  34. Begin
  35.   Writeln('Select Sound Card');
  36.   Writeln;
  37.   Writeln('  1. Gravis UltraSound');
  38.   Writeln('  2. Sound Blaster Pro');
  39.   Writeln('  3. Sound Blaster');
  40.   Writeln('  4. No Sound');
  41.   SelectSoundCard := (Ord(ReadKey) - Ord('0'));
  42. End;
  43.  
  44. Function SelectIOAddr: Integer;
  45.  
  46. Begin
  47.   Writeln;
  48.   Writeln('Select IO Address');
  49.   Writeln;
  50.   Writeln('  1. 210h ');
  51.   Writeln('  2. 220h ');
  52.   Writeln('  3. 230h ');
  53.   Writeln('  4. 240h ');
  54.   Writeln('  5. 250h ');
  55.   Writeln('  6. 260h ');
  56.   SelectIOAddr := $200+((Ord(ReadKey)-Ord('0'))*$10);
  57. End;
  58.  
  59. Function SelectIRQ : Integer;
  60.  
  61. Begin
  62.   Writeln;
  63.   Writeln('Select IRQ');
  64.   Writeln;
  65.   Writeln('  1. Irq 2');
  66.   Writeln('  2. Irq 3');
  67.   Writeln('  3. Irq 5');
  68.   Writeln('  4. Irq 7');
  69.   Writeln('  5. Irq 11');
  70.   Writeln('  6. Irq 12');
  71.   Case ReadKey of
  72.     '1' : SelectIRQ := 2;
  73.     '2' : SelectIRQ := 3;
  74.     '3' : SelectIRQ := 5;
  75.     '4' : SelectIRQ := 7;
  76.     '5' : SelectIRQ := 11;
  77.     '6' : SelectIRQ := 12;
  78.   End;
  79. End;
  80.  
  81. Function SelectDMA : Integer;
  82.  
  83. Begin
  84.   Writeln;
  85.   Writeln('Select DMA');
  86.   Writeln;
  87.   Writeln('  1. Dma 1');
  88.   Writeln('  2. Dma 3');
  89.   Writeln('  3. Dma 5');
  90.   Case ReadKey of
  91.     '1' : SelectDMA := 1;
  92.     '2' : SelectDMA := 3;
  93.     '3' : SelectDMA := 5;
  94.   End;
  95. End;
  96.  
  97.  
  98. Procedure InitializeMusic;
  99.  
  100. Var
  101.   ErrInit : Word;
  102.   SoundCardName : String;
  103.   IOAddr : Word;
  104.   DMA : Byte;
  105.   IRQ : Byte;
  106.   Diskfile : File;
  107.   EMSFlag : Word;
  108.   GDMH : GdmHeader;
  109.   MUSICChannels, ChannelCount, SampleRate : Word;
  110.  
  111. Begin
  112.   SoundEnabled := False;
  113. {$IFDEF NOTUNE}
  114.   Exit;
  115. {$ENDIF}
  116.   
  117. {$IFNDef Test}
  118.   Case SelectSoundCard of
  119.     1 : SoundCardName := 'GUS.MSE';
  120.     2 : SoundCardName := 'SBPRO.MSE';
  121.     3 : SoundCardName := 'SB1X.MSE';
  122.     4 : Exit;
  123.   End;
  124.   If Not(EMSExist) and (SoundCardName <> 'GUS.MSE')
  125.     Then Begin
  126.       Writeln('Sorry, this demo requires about 400K EMS memory to play the music. Please configure ');
  127.       Writeln('EMS memory and try again.');
  128.       Halt(0);
  129.     End;
  130.  
  131.   IOAddr := SelectIOAddr;
  132.   IRQ := SelectIRQ;
  133.   DMA := SelectDMA;
  134. {$ELSE}
  135.   SoundCardName := 'GUS.MSE';
  136.   IOAddr := $210;
  137.   DMA := 5;
  138.   IRQ := 12;
  139. {$ENDIF}
  140.   ErrInit := LoadMSE(SoundCardName, 0, 44, 8128, IOAddr, IRQ, DMA);
  141.   If ErrInit <> 0
  142.     Then Begin
  143.       Writeln('Error initializing music routines. Sound is not enabled.');
  144.       Delay(1000);
  145.       Exit;
  146.     End;
  147.   Assign(Diskfile, '4Morn.Gdm');
  148.   {$I-}
  149.   Reset(Diskfile, 1);
  150.   {$I+}
  151.   If IOResult <> 0
  152.     Then Begin
  153.       Writeln('Error loading module, Sound is not enabled.');
  154.       Delay(1000);
  155.       FreeMSE;
  156.       Exit;
  157.     End;
  158.   EMSFlag := 1;  { Use EMS memory }
  159.   ErrInit := LoadGDM(Diskfile, 0, EMSFlag, GDMH);
  160.   If ErrInit <> 0
  161.     Then Begin
  162.       Writeln('Error reading module, Sound is not enabled.');
  163.       Delay(1000);
  164.       FreeMSE;
  165.       Exit;
  166.     End;
  167.   MusicChannels := 0;            { Calculate the number of channels in song }
  168.   For ChannelCount := 1 to 32 do
  169.     Begin
  170.       If GDMH.PanMap[ChannelCount] <> $FF
  171.         Then MusicChannels := MusicChannels + 1;
  172.     End;
  173.   SampleRate := StartOutput(MusicChannels, 0);
  174.   SoundEnabled := True;
  175. End;
  176.  
  177. Procedure CloseMusic;
  178.  
  179. Var
  180.   Temp : Byte;
  181.   Count : Byte;
  182.  
  183. Begin
  184.   If SoundEnabled
  185.     Then Begin
  186.       For Count := 63 downto 0 do
  187.         Begin
  188.           Temp := MusicVolume(Count);
  189.           Delay(50);
  190.         End;
  191.       StopMusic;
  192.       StopOutput;
  193.       UnloadModule;
  194.       FreeMSE;
  195.     End;
  196. End;
  197.  
  198. End.